/**********************************************************************/
/**  Copyright (c) ECC labs. 2001-2002. All Rights Reserved.		 **/
/**********************************************************************/
/*
	binword.h
	Mark Papazyan

*/

#ifndef __CBINWORD_H
#define __CBINWORD_H

#include <iostream>
#include <string>
using namespace std;


#define LINUX
//#define WINDOWS
//#define BORLAND
//#define LEN64

#ifdef WINDOWS
	typedef unsigned __int64 u64;
#endif /*WINDOWS*/
	
#ifdef LINUX
	typedef unsigned long long int u64;
#endif /*LINUX*/

#ifdef LEN64
	typedef u64 t_src;
	#define MAX_LENGTH 64
	#define MAX_HEIGHT 128
#else
	typedef unsigned long t_src;
	#define MAX_LENGTH 32
	#define MAX_HEIGHT 64
#endif /*LEN64*/

#define I (t_src)1



typedef long t_cnt;
typedef char t_tab; //substitute series type
typedef unsigned long t_res;
typedef long t_len;



class CBinWord
{
public:

//Variables

	t_src num;
	t_len weight;
	t_len n;

//Constructor/Destructor

 	CBinWord(t_len k=MAX_LENGTH,t_src p=(t_src)0):n(k),num(p),weight(0){}
 	CBinWord(char* ch, t_len k=MAX_LENGTH):n(k),weight(0){num=bin2dec(ch);}

//Manipulations

	t_src bin2dec(char*);
	t_src bin2dec(string&);
	char* dec2bin();
	t_len wt();
	void next();
	void cyclic_shift(t_len, char where='r');

	void bit_set(t_len);
	inline void bit_clear(t_len);
	void bit_swap(t_len, t_len);
	t_res is_set(t_len);

//Operations

	CBinWord& operator+=(CBinWord&);
	CBinWord operator+(CBinWord&);
	CBinWord& operator^=(CBinWord&);
	CBinWord operator^(CBinWord&);
	bool operator==(CBinWord a);
	operator char*(){return dec2bin();}

};

//Input/Ouput

ostream& operator<<(ostream&, CBinWord&);
istream& operator>>(istream&, CBinWord&);

#ifndef BORLAND
ostream& operator<<(ostream& out, u64& a);


#ifdef WINDOWS
istream& operator>>(istream& in, u64& a);
#endif

#endif /*BORLAND*/

//Global

t_len d(CBinWord, CBinWord);

#endif

